import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int f1=0;
        int f2=1;
        while(n>f2){
            int f3=f1+f2;
            f1=f2;
            f2=f3;
        }
//当退出循环的时候 f2<n<=f3
        int min=Math.min(n-f1,f2-n);
        System.out.println(min);
    }
}
class Parenthesis {
    public boolean chkParenthesis(String A, int n) {
// write code here
        if(n%2!=0){
            return false;
        }
        Stack<Character> stack=new Stack<>();
        for (char c:A.toCharArray()){
            if(c=='('){
                stack.push(c);
            }else if(c==')'){
                if(stack.isEmpty()){
                    return false;
                }else if(stack.peek()=='('){
                    stack.pop();
                }
            }else{
                return false;
            }
        }
        return stack.isEmpty();
    }
}
public class Test0915 {
}
